Crystal Reports Integration

Generate PDF Report

Description
This example demonstrates how to integrate Crystal Reports with an Iron Speed Designer-application.
Variables
Crystal Report File
Select a crystal report file.
Button Control
Select a button
Applies to
P_Button Control class
Code
 
''' 
'''Override the ${Button Control}_Click and call DisplayReportAsPD() function
''' 
Public Overrides Sub ${Button Control}_Click(ByVal sender As Object, ByVal args As EventArgs)
    Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    crReportDocument.Load("${Crystal Report File}")
    DisplayReportAsPDF(crReportDocument)
End Sub
 
Applies to
P_Button Control class
Code
 
''' 
''' This function creates an instance of the Crystal Report in PDF format and displays it.
''' 
Private Sub DisplayReportAsPDF( _
    ByVal reportObject As _
    CrystalDecisions.CrystalReports.Engine.ReportDocument)
    
    ' Declare the necessary Crystal Reports objects.
    Dim dbTable As CrystalDecisions.CrystalReports.Engine.Table
    Dim dbLogin As CrystalDecisions.Shared.TableLogOnInfo
    Dim crExportOptions As ExportOptions
    Dim crDiskFileDestinationOptions As DiskFileDestinationOptions

    ' Add login information if needed.
    'reportObject.SetDatabaseLogon("UserID", "password")

    ' Create a temporary file to hold the report.
    ' -- use the session ID in the filename to  avoid process conflicts
    ' -- use a built-in Iron Speed utility function (and the "MapPath" method) to get the current 
    ' -- application's root path
    
    Dim fileName As String 
    fileName = _
                Me.Page.Server.MapPath( _
                BaseClasses.Configuration.ApplicationSettings.Current.AppRootPath) _
                & "\" & me.Page.Session.SessionID.ToString & ".pdf"

    ' Define the Crystal Report output options.
    crDiskFileDestinationOptions = New DiskFileDestinationOptions
    crDiskFileDestinationOptions.DiskFileName = fileName
    crExportOptions = reportObject.ExportOptions
    
    With crExportOptions
        .DestinationOptions = crDiskFileDestinationOptions
        .ExportDestinationType = ExportDestinationType.DiskFile
        .ExportFormatType = ExportFormatType.PortableDocFormat
    End With

    ' Export the document to the temporary file.
    reportObject.Export()

    ' Create the HTTP Response as PDF and output the file.
    me.Page.Response.ClearContent()
    me.Page.Response.ClearHeaders()
    me.Page.Response.ContentType = "application/pdf"
    me.Page.Response.WriteFile(fileName)
    me.Page.Response.Flush()

    ' Clean up the Response object and delete the temporary file.
    me.Page.Response.Close()
    System.IO.File.Delete(fileName)
End Sub
     

Terms of Service Privacy Statement